package com.ctshk.rpc.localfun.config;

import com.ctshk.common.constant.RedissonConfigConstants;
import org.redisson.Redisson;
import org.redisson.api.RedissonClient;
import org.redisson.config.Config;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

import java.io.IOException;

@Configuration
public class RedissonConfig {
    @Value("${spring.redis.host}")
    String host;
    @Value("${spring.redis.port}")
    String port;
    @Value("${spring.redis.password}")
    String password;

    /**
     * @return
     * @throws IOException
     */
    @Bean(destroyMethod = "shutdown")
    RedissonClient redisson() throws IOException {
        Config config = new Config();
        config.useSingleServer()
                .setAddress(RedissonConfigConstants.REDISSON_PREFIX + host + RedissonConfigConstants.REDISSON_JOINER + port)
                .setPassword(password);
        return Redisson.create(config);
    }
}
 